package com.sumainfor.pc.epc.controller.master;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.epc.service.ReceiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/master/receive")
public class ReceiveController implements Serializable{

    @Autowired
    private ReceiveService receiveService;

    /**
     * 功能描述:
     * 分页查询领用单列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/11/3 21:22
     */
    @RequestMapping(value = "/getReceiveList",method = RequestMethod.GET)
    public JsonResult getReceiveList(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=receiveService.getReceiveListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=receiveService.getReceiveList(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     * 由后台发起的申请领用单
     * @param params
     * @return
     */
    @RequestMapping(value = "/addReceivePC",method = RequestMethod.POST)
    public JsonResult addReceivePC(@RequestBody Map<String,Object> params){
        JsonResult result=new JsonResult();
        if(receiveService.addReceivePC(params)>0){
            result.putSuccess("申请领用单成功！");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }
    /**
     * 更具领用单查询对应的领用备件
     */
    @RequestMapping(value = "/getReceiveGoodList",method = RequestMethod.GET)
    public JsonResult getReceiveGoodList(@RequestParam Map<String,Object> params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=receiveService.getReceiveGoodList(params);
        if(list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

}
